package com.apes.fn.server.productRequire;

import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.util.ApesConst;
import com.apes.scm.masterdata.enumeration.model.Enumeration;
import com.apes.scm.masterdata.party.model.PartyRole;
import com.apes.scm.masterdata.product.model.Product;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.Date;

@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = RequireTerminationReson.CONST_TABLE_NAME)
public class RequireTerminationReson extends BaseModel {
    public static final String CONST_TABLE_NAME = "stock_require_reson";

    @Id
    @Column(name = "id")
    @ApesGenerator(code = CONST_TABLE_NAME, padding = 1, name = "要货终止原因")
    private String id;

    @ManyToOne(optional = false)
    @JoinColumn(name = "product_require_id", referencedColumnName = "id", nullable = false)
    @Comment("主表单号")
    private ProductRequire productRequire;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "product_id", referencedColumnName = "id", nullable = false)
    @Comment("商品")
    private Product product;

    @Column(name = "termination_qty", nullable = false, columnDefinition = ApesConst.FIELD_QTY_16_4_0)
    @Comment("单次终止数量")
    private double terminationQty = 0;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "termination_reson", referencedColumnName = "id")
    @Comment("终止原因")
    private Enumeration terminationReson;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "repeal_uid", referencedColumnName = "id")
    @Comment("终止人")
    private PartyRole repealUid;

    @Column(name = "repeal_date")
    @Comment("终止日期")
    private Date repealDate;

}
